home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / datatypes / dfadt / source / dfadt_libinit.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  5KB  |  256 lines

  1. /* $Revision Header built automatically *************** (do not edit) ************
  2. **
  3. ** © Copyright by Dirk Federlein
  4. **
  5. ** File             : Work:programming/dfa/Sourcen_V2.3/Datatypes/dfadt_libinit.c
  6. ** Created on       : Dienstag, 14.03.95 15:08:08
  7. ** Created by       : Dirk Federlein
  8. ** Current revision : V1.0
  9. **
  10. **
  11. ** Purpose
  12. ** -------
  13. **     Inits the datatype class
  14. **
  15. ** Revision V1.0
  16. ** --------------
  17. ** created on Dienstag, 14.03.95 15:08:08  by  Dirk Federlein.   LogMessage :
  18. **     --- Initial release ---
  19. **
  20. *********************************************************************************/
  21.  
  22. #include "all_includes.h"
  23. #include "dfadt.h"
  24.  
  25. #include "dfa.datatype_rev.h"
  26.  
  27. char                    version[]        = VERSTAG;
  28.  
  29. struct Library * __asm __saveds    LibInit(register __a0 BPTR Segment, register __d0 struct Library *Base);
  30. struct Library * __asm __saveds    LibOpen(register __a6 struct Library *Base);
  31. BPTR __asm __saveds                LibExpunge(register __a6 struct Library *Base);
  32. BPTR __asm __saveds                LibClose(register __a6 struct Library *Base);
  33. LONG __asm __saveds                LibNull(register __a6 struct Library *Base);
  34.  
  35. Class * __saveds                GetClassEngine(VOID);
  36.  
  37. BPTR                            LibSegment    = NULL;
  38. UBYTE __aligned                    LibName[]    = "dfa.datatype";
  39. UBYTE __aligned                    LibID[]        = VSTRING;
  40.  
  41.  
  42. struct ExecBase            * SysBase;
  43. struct DosLibrary        * DOSBase;
  44. struct IntuitionBase    * IntuitionBase;
  45. struct GfxBase            * GfxBase;
  46. struct Library            * LayersBase,
  47.                         * UtilityBase,
  48.                         * DataTypesBase,
  49.                         * SuperClassBase;
  50.  
  51. Class                    * TextClass;
  52.  
  53. struct SignalSemaphore    LockSemaphore;
  54.  
  55.  
  56. APTR LibVectors[] =  /* die Sprungtabelle */
  57. {
  58.     LibOpen,
  59.     LibClose,
  60.     LibExpunge,
  61.     LibNull,
  62.     GetClassEngine,
  63.     (APTR)-1
  64. };
  65.  
  66. struct 
  67.     ULONG DataSize; 
  68.     APTR Table; 
  69.     APTR Data; 
  70.     struct Library * (*Init)(); 
  71. } __aligned LibInitTab =
  72.     {
  73.         sizeof(struct Library),
  74.         LibVectors,
  75.         NULL,
  76.         LibInit
  77.     };
  78.  
  79. struct Library * __asm __saveds
  80. LibInit(register __a0 BPTR Segment,register __d0 struct Library *Base)
  81. {
  82.  
  83.     Base -> lib_Node . ln_Type  = NT_LIBRARY;
  84.     Base -> lib_Node . ln_Name  = LibName;
  85.     Base -> lib_Flags           = LIBF_CHANGED | LIBF_SUMUSED;
  86.     Base -> lib_Version         = VERSION;
  87.     Base -> lib_Revision        = REVISION;
  88.     Base -> lib_IdString        = LibID;
  89.  
  90.     LibSegment = Segment;
  91.     SysBase = *(struct ExecBase **)4;
  92.     InitSemaphore(&LockSemaphore);
  93.  
  94.  
  95.     return(Base);
  96. }
  97.  
  98.  
  99. struct Library * __asm __saveds
  100. LibOpen(register __a6 struct Library *Base)
  101. {
  102.     Base -> lib_OpenCnt++;
  103.     Base -> lib_Flags &= ~LIBF_DELEXP;
  104.  
  105.  
  106.     if(Base -> lib_OpenCnt == 1)
  107.     {
  108.         ObtainSemaphore(&LockSemaphore);
  109.  
  110.         if(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",37))
  111.         {
  112.             if(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37))
  113.             {
  114.                 if(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",39))
  115.                 {
  116.                     if(UtilityBase = OpenLibrary("utility.library",0))
  117.                     {
  118.                         if(LayersBase = OpenLibrary("layers.library",0))
  119.                         {
  120.                             if(DataTypesBase = OpenLibrary("datatypes.library",0))
  121.                             {
  122.                                 if(SuperClassBase = OpenLibrary("datatypes/text.datatype",0))
  123.                                 {
  124.                                     if(TextClass = MakeClass("dfa.datatype", TEXTDTCLASS,NULL,sizeof(struct DDTData),NULL))
  125.                                     {
  126.                                         extern ULONG ClassDispatch();
  127.  
  128.  
  129.                                         TextClass->cl_Dispatcher.h_Entry = (HOOKFUNC)ClassDispatch;
  130.                                         TextClass->cl_UserData = (ULONG) Base;
  131.                                         AddClass(TextClass);
  132.                                         ReleaseSemaphore(&LockSemaphore);
  133.                                         return(Base);
  134.                                     }
  135.  
  136.                                     CloseLibrary(SuperClassBase);
  137.                                     SuperClassBase = NULL;
  138.                                 }
  139.                                 CloseLibrary(DataTypesBase);
  140.                                 DataTypesBase = NULL;
  141.                             }
  142.                             CloseLibrary(LayersBase);
  143.                             LayersBase = NULL;
  144.                         }
  145.                         CloseLibrary(UtilityBase);
  146.                         UtilityBase = NULL;
  147.                     }
  148.                     CloseLibrary(GfxBase);
  149.                     GfxBase = NULL;
  150.                 }
  151.                 CloseLibrary(IntuitionBase);
  152.                 IntuitionBase = NULL;
  153.             }
  154.             CloseLibrary(DOSBase);
  155.             DOSBase = NULL;
  156.         }
  157.  
  158.         ReleaseSemaphore(&LockSemaphore);
  159.         return(NULL);
  160.  
  161.     }
  162.     else
  163.         return(Base);
  164. }
  165.  
  166. BPTR __asm __saveds LibExpunge(register __a6 struct Library *Base)
  167. {
  168.     BPTR TempSegment = LibSegment;
  169.  
  170.  
  171.     if(!Base -> lib_OpenCnt && TempSegment)
  172.     {
  173.         Remove((struct Node *)Base);
  174.         FreeMem((BYTE *)Base - Base -> lib_NegSize, Base -> lib_NegSize + Base -> lib_PosSize);
  175.         LibSegment = NULL;
  176.         return(TempSegment);
  177.     }
  178.     else
  179.     {
  180.         Base -> lib_Flags |= ~LIBF_DELEXP;
  181.         return(NULL);
  182.     }
  183. }
  184.  
  185. BPTR __asm __saveds LibClose(register __a6 struct Library *Base)
  186. {
  187.  
  188.     if(!(Base -> lib_OpenCnt--))
  189.         Base -> lib_OpenCnt = 0;
  190.  
  191.  
  192.     if(!Base -> lib_OpenCnt)
  193.     {
  194.         ObtainSemaphore(&LockSemaphore);
  195.  
  196.         if(TextClass)
  197.         {
  198.             RemoveClass(TextClass);
  199.             FreeClass(TextClass);
  200.             TextClass = NULL;
  201.         }
  202.  
  203.         CloseLibrary(SuperClassBase);
  204.         SuperClassBase = NULL;
  205.  
  206.         CloseLibrary(DataTypesBase);
  207.         DataTypesBase = NULL;
  208.  
  209.         CloseLibrary(LayersBase);
  210.         LayersBase = NULL;
  211.  
  212.         CloseLibrary(UtilityBase);
  213.         UtilityBase = NULL;
  214.  
  215.         CloseLibrary(IntuitionBase);
  216.         IntuitionBase = NULL;
  217.  
  218.         CloseLibrary(GfxBase);
  219.         GfxBase = NULL;
  220.  
  221.         CloseLibrary(DOSBase);
  222.         DOSBase = NULL;
  223.  
  224.         ReleaseSemaphore(&LockSemaphore);
  225.     }
  226.  
  227.     if((Base -> lib_Flags & LIBF_DELEXP) && !Base -> lib_OpenCnt)
  228.         return(LibExpunge(Base));
  229.  
  230.     return(NULL);
  231. }
  232.  
  233. LONG __asm __saveds
  234. LibNull(register __a6 struct Library *Base)
  235. {
  236.  
  237.     return(NULL);
  238. }
  239.  
  240. Class * __saveds GetClassEngine()
  241. {
  242.     Class *class;
  243.  
  244.     ObtainSemaphore(&LockSemaphore);
  245.  
  246.     class = TextClass;
  247.  
  248.     ReleaseSemaphore(&LockSemaphore);
  249.  
  250.     return(class);
  251.  
  252.  
  253. }
  254.  
  255.